/* t_str.cpp : test dgnsc time
 * Copyright (C) 2011 drangon <drangon.zhou@gmail.com>
 * 2011-09
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <dgnsc/str.h>

#include "gtest.h"

#include <stdio.h>
#include <assert.h>
#include <string.h>

TEST( str, str )
{
	dgn_str_t s1, s2, s3;

	s1 = dgn_str_init( 20 );
	s2 = dgn_str_init_dup( s1 );
	s3 = dgn_str_init_c( "hello", 4 );

	int cap = dgn_str_reserve( s1, 30 );
	EXPECT_TRUE( cap > 30 );
	cap = dgn_str_reserve( s1, 100 );
	EXPECT_TRUE( cap == 100 );

	int len = dgn_str_len( s3 );
	EXPECT_TRUE( len == 4 );
	const char * p = dgn_str_c( s3 );
	int tmp = strcmp( p, "hell" );
	EXPECT_TRUE( tmp == 0 );

	dgn_str_assign( s1, s3 );
	dgn_str_assign_c( s2, "hello", -1 );

	dgn_str_append( s1, s2 );
	dgn_str_append_c( s2, "world", -1 );
	dgn_str_assign_fmt( s3, "hello %s %d", "world", 4 );
	dgn_str_append_fmt( s3, ", happy %s %d", "world", 8 );

	dgn_str_assign_c( s1, "hello", -1 );
	dgn_str_assign( s2, s1 );
	tmp = dgn_str_cmp( s1, s2 );
	tmp = dgn_str_cmp_c( s1, "hello", -1 );
	tmp = dgn_str_casecmp( s1, s2 );
	tmp = dgn_str_casecmp_c( s1, "HELLO", -1 );

	dgn_str_fini( s1 ), s1 = NULL;
	dgn_str_fini( s2 ), s2 = NULL;
	dgn_str_fini( s3 ), s3 = NULL;
}

